package com.neborosoft.FlyingDog.logic.database.content.identified;

import com.neborosoft.lib.collections.algorithms.Comparators;

import java.util.Comparator;

/**
 * Project: FlyingDog
 * User: stikhonenko
 * Date: 3/11/13
 * Time: 6:39 PM
 */
public final class AudioComparators {
    public static <T extends ArtCollection> Comparator<T> artCollectionByName(){
        return new Comparator<T>() {
            @Override
            public int compare(T a, T b) {
                String nameA = a.getName();
                String nameB = b.getName();
                return nameA.compareTo(nameB);
            }
        };
    }

    public static <T extends ArtCollection> Comparator<T> artCollectionByNameReverseOrder(){
        return Comparators.reverseComparator(AudioComparators.<T>artCollectionByName());
    }

    private static Comparator<Audio> audioArtistNameComparator(){
        return new Comparator<Audio>() {
            @Override
            public int compare(Audio a, Audio b) {
                String artistNameA = a.getArtistName();
                String artistNameB = b.getArtistName();
                return artistNameA.compareTo(artistNameB);
            }
        };
    }

    private static Comparator<Audio> audioTotalListeningDurationComparator(){
        return new Comparator<Audio>() {
            @Override
            public int compare(Audio a, Audio b) {
                return Float.compare(a.getTotalListeningDuration(), b.getTotalListeningDuration());
            }
        };
    }

    public static Comparator<Audio> audioByName(){
        return Comparators.comparatorCombination(AudioComparators.<Audio>artCollectionByName(),
                audioArtistNameComparator());
    }

    public static Comparator<Audio> audioByNameReverseOrder(){
        return Comparators.reverseComparator(audioByName());
    }

    public static Comparator<Audio> audioByArtistName(){
        return Comparators.comparatorCombination(audioArtistNameComparator(),
                AudioComparators.<Audio>artCollectionByName());
    }

    public static Comparator<Audio> audioByArtistNameReverseOrder(){
        return Comparators.reverseComparator(audioByArtistName());
    }

    public static Comparator<Audio> audioByTotalListeningDuration(){
        return Comparators.comparatorCombination(audioTotalListeningDurationComparator(),
                audioByName());
    }

    public static Comparator<Audio> audioByTotalListeningDurationReverseOrder(){
        return Comparators.reverseComparator(audioByTotalListeningDuration());
    }
}
